package src.Fifteen;

import javax.swing.*;

public class PriorityTest extends JFrame {

    private Thread threadA;
    private Thread threadB;
    private Thread threadC;
    private Thread threadD;
    private JProgressBar progressBar;
    private JProgressBar progressBar2;
    private JProgressBar progressBar3;
    private JProgressBar progressBar4;
    public PriorityTest(){
        threadA = new Thread(new MyThread(progressBar));
        threadB = new Thread(new MyThread(progressBar2));
        threadC = new Thread(new MyThread(progressBar3));
        threadD = new Thread(new MyThread(progressBar4));

    }

    public static void main(String[] args) {
        init(new PriorityTest(),100,100);
    }

    private static void init(JFrame jFrame,Integer width,Integer height){
        jFrame.setSize(width,height);
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void setPriority(String threadName,int priority,Thread t){
        t.setPriority(priority);
        t.setName(threadName);
        t.start();
    }

    private final class MyThread implements Runnable{
        private final JProgressBar bar;
        int count = 0;

        private MyThread(JProgressBar bar){
            this.bar = bar;
        }
        @Override
        public void run() {
            while (true){
                bar.setValue(count+=10);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    System.out.println("当前线程被中断");
                }
            }
        }
    }
}
